<?php
require_once("scripts/cart_engine.php");
require_once("scripts/hiding_place_engine.php");
require_once("scripts/single_product.php");

removeAllExpired();
if (isset($_POST["action"]))
{
	$action = $_POST["action"];
}
else if (isset($_GET["action"]))
{
	$action = $_GET["action"];
}
else
{
	$action = "";
}
$prodId = -1;
switch ($action)
{
	case "addtocart" : 			$prodID = isset($_POST["id"]) ? $_POST["id"] : "";
								addToCart($prodID);
								break;
	case "removefromcart" :		$prodID = isset($_GET["id"]) ? $_GET["id"] : "";
								removeFromCart($prodID);
								break;
	case "addtohiding" :		$prodID = isset($_POST["id"]) ? $_POST["id"] : "";
								addToHidingPlace($prodID);
								break;
	case "removefromhiding" :	$prodID = isset($_GET["id"]) ? $_GET["id"] : "";
								removeFromHidingPlace($prodID);
								break;
	case "fromcarttohiding" :	$prodID = isset($_GET["id"]) ? $_GET["id"] : "";
								fromCartToHiding($prodID);
								break;
	case "fromhidingtocart" :	$prodID = isset($_GET["id"]) ? $_GET["id"] : "";
								fromHidingToCart($prodID);
								break;
	case "buy" :				buy();
								break;
}

?>
<div id="cart">
	<h3>Twój koszyk</h3>
	<?php
	$cartContent = getCart();
	for ($i = 0; $i < count($cartContent); $i++)
	{
		displayProductOnCart($cartContent[$i]);
	}
	?>
	<p><b><small>Liczba produktów w koszyku: <?php echo count($cartContent);?> </small><br>
	<small>Sumaryczna cena produktów w koszyku: <?php echo countCartPrice();?> zł</small></b></p>
	<?php if (count($cartContent) > 0) : ?>
	<center>
	<form id="buy" name="buy" action="index.php?content=cart_hiding_place" method="POST">
		<input name="action" type="hidden" value="buy">
		<input name="submit" type="submit" value="Kup!">
	</form>
	</center>
	<?php endif; ?>
</div>

<div id="hidingPlace">
	<h3>Twoja przechowalnia</h3>
	<?php 
	$hidingPlaceContent = getHidingPlace();
	for ($i = 0; $i < count($hidingPlaceContent); $i++)
	{
		displayProductInHidingPlace($hidingPlaceContent[$i]);
	}
	?>
	<p><b><small>Liczba produktów w przechowalni: <?php echo count($hidingPlaceContent);?></small><br>
	<small>Sumaryczna cena produktów w przechowalni: <?php echo countHidingPlacePrice();?> zł</small></b></p>
</div>
